//导入APP版本信息
import {_appVer} from '../../main.js';
import {_verContent} from '../../main.js';
import {_createTime} from '../../main.js';

export default {
	data() {
		return {
			id: '',
			phone:'',
			nickname: '',
			password:'',
			//新密码
			newPassword1:'',
			//确认新密码
			newPassword2:'',
			headImg: '',
			downList: [{
					iconPath: "home",
					selectedIconPath: "home-fill",
					text: '消息',
					customIcon: false,
					pagePath: '/pages/index/index'
				},
				{
					iconPath: "man-add",
					selectedIconPath: "man-add-fill",
					text: '添加',
					customIcon: false,
					pagePath: '/pages/add/add'
				},
				{
					iconPath: "account",
					selectedIconPath: "account-fill",
					text: '我的',
					customIcon: false,
					pagePath: '/pages/user/user'
				}
			],
			current: 0,
			
			//APP本地版本信息
			L_appVer:_appVer,
			L_verContent:_verContent,
			L_createTime:_createTime,
			
			//APP最新版本信息
			appVer:'',
			verContent:'',
			url:'',
			createTime:'',
			
			//APP全部版本信息
			appVerList:[],
			
			//APP是否有更新
			isUpdateApp:true,
			
			//是否显示用户信息更新页面
			updateUserShow:false,
			//是否显示版本信息页面
			verShow:false
		}
	},
	onShow() {
		this.headImg = uni.getStorageSync('headImg');
		this.nickname = uni.getStorageSync('nickname');
		this.id = uni.getStorageSync('userId');
	},
	methods: {
		async beforeSwitch(index) {
			console.log(index)
			switch (index) {
				case 0:
					uni.reLaunch({
						url: '/pages/index/index',
					});
					break;
				case 1:

					break;
				case 2:

					break;
			}
			return true;
		},
		returnLogin() {
			uni.setStorage({
				key: 'userId',
				data: '',
				success: function() {

				}
			});
			uni.setStorage({
				key: 'token',
				data: '',
				success: function() {

				}
			});
			uni.setStorage({
				key: 'headImg',
				data: '',
				success: function() {

				}
			});
			uni.setStorage({
				key: 'nickname',
				data: '',
				success: function() {

				}
			});
			uni.navigateTo({
				url: '/pages/login/login',
			});
		},
		//打开个人信息更新页面
		update(){
			this.$request('/User/queryUserById', {
				// 传参参数名：参数值,如果没有，就不需要传
				"id": this.id
			}).then(res => {
				if (res.code == 200) {
					this.phone = res.data.phone;
					this.nickname = res.data.nickname;
					this.headImg = res.data.headImg;
					this.updateUserShow = true;
				}
			})
		},
		//更新个人信息
		updateUser(){
			this.$request('/User/updateUserById', {
				// 传参参数名：参数值,如果没有，就不需要传
				"id": this.id,
				"nickname":this.nickname,
				"phone":this.phone,
				"headImg":this.headImg
			}).then(res => {
				if (res.code == 200) {
					uni.showToast({
						title: '修改成功',
						icon: 'none',
						duration: 2000
					});
					this.updateUserShow = false;
				}
			})
		},
		//更新密码
		updatePassword(){
			
		},
		//打开版本信息页面
		ver(){
			this.$request('/AppVer/queryNewAppVer', {
				// 传参参数名：参数值,如果没有，就不需要传
				"null": "",
			}).then(res => {
				if (res.code == 200) {
					
					if(this.L_appVer === res.data.appVer){
						this.isUpdateApp = true;
					}
					else{
						this.isUpdateApp = false;
					}
					
					this.appVer = res.data.appVer;
					this.verContent = res.data.verContent;
					this.url = res.data.url;
					this.createTime = res.data.createTime;
					
					this.verShow = true;
				}
			})
		}
	}
}
